<template>
  <div class="dingdan">
    <div class="head">
      <p>订单列表</p>
    </div>
    <div class="mid">
      <ul>
        <li class="quan" v-for="item in list" :key="item.list">
          <div class="hao">
            <p>外卖订单:{{item.no}}</p>
            <van-icon class="ico" @click="del(item._id)" name="close" />
          </div>

          <div class="xiang">
            <div class="xl">
              <h6>{{item.regions+item.address}}</h6>
              <p>{{item.receiver}}</p>
            </div>
            <div class="xr">
              <p>{{item.createdAt}}</p>
            </div>
          </div>

          <div class="qian">
            <p>￥<span>{{item.price}}</span></p>
            <button class="cha" @click="view(item._id)">查看详情</button>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
import { orders,delorders } from '../api/order'

export default {
  data() {
    return {
      list: []
    }
  },
  async created() {
    const res = await orders();
    this.list = res.data.orders;
    console.log(this.list);

  },
  methods: {
    view(id) {
      this.$router.push({name:'orderDetail',  query:{id}})
    },
    del(id) {
      delorders(id).then(()=>{
        this.$router.go(0);
      });
    }
  }

}
</script>
<style scoped>
.dingdan{
  display: flex;
  flex-direction: column;
  width: 100%;
}
.head{
  height: 50px;
  border-bottom: solid 1px gainsboro;
}
.head p{
  margin: 0;
  text-align: center;
  line-height: 50px;
  font-size: 18px;
  font-weight: bolder;
}
.mid{
  flex: 1;
  overflow: auto;
}
.quan{
  padding: 12px 15px;
  display: flex;
  height: 150px;
  flex-direction: column;
  border-bottom: solid 1px gainsboro;
}
.hao p{
  margin: 0px;
  line-height: 30px;
  font-size: 14px;
}
.xiang p{
  margin: 0px;
  margin: 8px 0;
}
.qian p{
  margin: 0px;
}
.qian span{
  color: red;
  font-size: 18px;
}
.xr p{
  width: 120px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.xl h6{
  margin: 0px;
  width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 14px;
}
.ico{
  margin-top: 8px;
  color:red;
}
.hao{
  display: flex;
  height: 30px;
  line-height: 30px;
  justify-content: space-between;
  border-bottom: solid 1px ghostwhite;
}
.xiang{
  display: flex;
  justify-content: space-between;
  height: 50px;
  padding:10px 5px;
}
.qian{
  display: flex;
  justify-content: space-between;
  height: 50px;
}
.qian p{
  line-height: 50px;
}
.cha{
  display: block;
  width: 80px;
  height: 30px;
  margin-top: 9px;
}
</style>
